package com.xk.controller;

import com.cms.common.core.web.domain.Response;
import com.cms.common.log.annotation.Log;
import com.cms.common.log.enums.BusinessType;
import com.xk.domain.dto.*;
import com.xk.domain.vo.CollegeClassVo;
import com.xk.domain.vo.YearTypeVo;
import com.xk.service.CollegeClassService;
import com.xk.service.YearTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
@RequestMapping("/admin")
public class AdminController {
    /**
     * 班级服务
     */
    private final CollegeClassService collegeClassService;

    /**
     * 年度服务
     */
    private final YearTypeService yearTypeService;

    /**
     * 创建班级
     */
    @Log(title = "创建班级", businessType = BusinessType.INSERT)
    // 权限格式为：模块:功能:操作
//    @RequiresPermissions("qu:admin:createClass")
    @PostMapping("/createClass")
    public Response createClass(@RequestBody @Valid CreateClassDto createClassDto) {
        return collegeClassService.createClass(createClassDto);
    }

    /**
     * 查询班级列表
     */
    @Log(title = "导出班级", businessType = BusinessType.EXPORT)
    // 权限格式为：模块:功能:操作
//    @RequiresPermissions("qu:admin:exportClass")
    @GetMapping("/exportClass")
    public Response<PageDTO<CollegeClassVo>> exportClass(@Valid  CollegeClassDto collegeClassDto) {
        return Response.success(collegeClassService.exportClass(collegeClassDto));
    }
    /**
     * 创建年度
     */
    @Log(title = "创建年度", businessType = BusinessType.INSERT)
    // 权限格式为：模块:功能:操作
    //    @RequiresPermissions("qu:admin:createYear")
    @PostMapping("/createYear")
    public Response createYear(@RequestBody @Valid CreationTimeDto creationTimeDto) {
        return yearTypeService.createYear(creationTimeDto);
    }

    /**
     * 返回年度列表
     */
    @Log(title = "查询年度", businessType = BusinessType.EXPORT)
    // 权限格式为：模块:功能:操作
    //    @RequiresPermissions("qu:admin:queryYear")
    @GetMapping("/queryYear")
    public Response<PageDTO<YearTypeVo>> queryYear(QueryYearDto queryYearDto) {
        return Response.success(yearTypeService.queryYear(queryYearDto));
    }

    /**
     * 根据id年度修改
     */
    @Log(title = "修改年度", businessType = BusinessType.UPDATE)
    // 权限格式为：模块:功能:操作
    //    @RequiresPermissions("qu:admin:updateYear")
    @PutMapping("/updateYear")
    public Response updateYear( @RequestBody @Valid UpdateYearDto updateYearDto) {
        return yearTypeService.updateYear(updateYearDto);
    }
    /**
     * 根据id删除年度
     * @return
     */
    @Log(title = "删除年度", businessType = BusinessType.DELETE)
    // 权限格式为：模块:功能:操作
    //    @RequiresPermissions("qu:admin:deleteYear")
    @DeleteMapping("/deleteYear/{yearTypeId}")
    @Transactional
    public Response deleteYear(@PathVariable("yearTypeId") Long yearTypeId) {
        return yearTypeService.removeById(yearTypeId)?Response.success("删除成功"):Response.error("删除失败");
    }


}
